#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

const int N = 110;

int dp[N][N];
int n;
int row, col;

int main()
{
    cin >> n;
    while (n -- )
    {
        cin >> row >> col;
        for (int i = 1; i <= row; i ++)
        {
            for (int j = 1; j <= col; j ++)
            {
                cin >> dp[i][j];
                dp[i][j] += max(dp[i - 1][j], dp[i][j - 1]);
            }
        }
        cout << dp[row][col] << endl;
    }

    
    return 0;
}
